angular.module('inspinia').controller('vipRangeCtrl',function($scope, $http, $state){

	$scope.categoryTypes = [{text:"全部",value:null}, {text:"最高值",value:"1"},{text:"平均值",value:"2"},{text:"最低值",value:"3"}];

	$scope.info = {'vip':{},'non':{},'trans':{}};
	$scope.selectTargetRange = function(){
		$http.post('policyTarget/selectTargetRange', {headers: {'Content-Type': 'application/x-www-form-urlencoded'}}
		).success(function(result){
			$scope.info = result.data;
		}).error(function(){
		});
	};
	$scope.selectTargetRange();


	$scope.submit = function(){
		$scope.submitting = true;

		if(parseInt($scope.info.vip.zDays) > parseInt($scope.info.vip.kDays) || parseInt($scope.info.trans.zDays) > parseInt($scope.info.trans.kDays) || parseInt($scope.info.non.zDays) > parseInt($scope.info.non.kDays)){
			$scope.notice("不限旬不限类取天数不能大于数据取值范围");
			return;
		}

		if(parseInt($scope.info.vip.kDays) > 90 || parseInt($scope.info.trans.kDays) > 90 || parseInt($scope.info.non.kDays) > 90){
			$scope.notice("数据取值范围（日）只支持（1-90天）");
			return;
		}

		$http.post("policyTarget/updateTargetRange",$scope.info)
			.success(function(result){
			if(result.status){
				$scope.notice("新增成功");
				$state.transitionTo('org.policyTarget',null,{reload:true});
			} else {
				$scope.notice("新增失败");
			}
		});
	}



});